import { defineStore } from 'pinia';
export const useUserStore = defineStore('user', {
  state: () => ({
    name: '开始',
    selected :['John', 'Jane', 'Jim', 'Jack', 'Stack', 'Timi', 'William'],
  }),
  actions: {
    setName() {
      if (this.selected.length === 0) {
        this.name = '已用完';
        return false;
      } else {
        let index = Math.floor(Math.random() * this.selected.length);
        this.name =  this.selected[index];
        //删除数组中的索引为index的元素
        this.selected.splice(index, 1);
      }
    },
    resetName() {
      this.name = '开始';
      this.selected = ['John', 'Jane', 'Jim', 'Jack', 'Stack', 'Timi', 'William'];
    }
  },
});